package com.training.service;

import com.jfinal.plugin.activerecord.Page;
import com.training.common.model.Student;
import com.training.common.model.Train;

import java.util.List;

public class StudentServiceImp implements StudentService{

    public Page<Student> getStudentPage(int pageNumber, int pageSize, String name,String number, String class_id){
        return Student.dao.getStudentPage(pageNumber,pageSize,name,number,class_id);
    }

    @Override
    public Page<Student> getStudentTrainPage(String classids, int pageNumber, int pageSize, String number, String name) {
        return Student.dao.getStudentTrainPage(classids,pageNumber, pageSize, number, name);
    }

    @Override
    public List<Student> getStudentListTrainid(String trainid, String number) {
        String[] trainids = trainid.split(",");
        String classids = "";
        for(int i = 0 ; i < trainids.length ; i++){
            Train train = Train.dao.findById(trainids[i]);
            if(train!=null){
                classids += train.getClassids();
                if(i+1 < trainids.length){
                    classids += ",";
                }
            }else{
                classids = "0";
            }
        }
        List<Student> studentList = Student.dao.getStudentList(classids,number);
        return studentList;
    }
}
